unit uAbstractControl;

interface
uses
  SQLExpr,Classes,Forms,Variants,SysUtils;
const
  MO_ExceptionMsg='Meeting Organizer Error: '+#13;
type
  TAbstractControl=class(TComponent)
private
  fDBConnection: TSQLConnection;
  fTD: TTransactionDesc;
  procedure SetDBConnection(const Value: TSQLConnection);
  procedure SetTD(const Value: TTransactionDesc);
  function GetTD:TTransactionDesc;
  function GetDBConnection:TSQLConnection;
published
    public
      constructor Create(AOwner: TComponent);override;
      destructor Destroy;override;
      property DBConnection:TSQLConnection read FDBConnection write SetDBConnection;
      property TD: TTransactionDesc read FTD write SetTD;
      procedure CreateDefaultForm;virtual;abstract;
      procedure CreateDefaultDM;virtual;abstract;
      function DataFormat(Data:Variant;DataType:char):string;

  end;
implementation

uses uMainForm;
constructor TAbstractControl.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  DBConnection:=TMainForm(Application.MainForm).DBConnection;

  fTD.GlobalID:=1;
  fTD.TransactionID:=1;
  fTD.IsolationLevel:=xilREADCOMMITTED;

  CreateDefaultDM;
end;


{ TAbstractControl }

function TAbstractControl.DataFormat(Data: Variant; DataType: char): string;
begin
  if VarIsEmpty(Data) then
    begin
      Result:='';
    end
  else
    begin
      if DataType='c' then
        begin
          Result:=#39+Data+#39;
        end
      else
      if DataType='D' then
      begin
         Result:='CAST(' +#39+FormatDateTime('mm/dd/yyyy',
         VarToDateTime(Data))+#39+'AS DATE)'
      end
      else
      if DataType='T' then
        begin
          Result:='CAST('+#39+FormatDateTime('mm/dd/yyyy hh:nn:ss',
            VarToDateTime(Data))+#39+'AS TIMESTAMP)'
        end
        else
        if DataType = 'N' then
        begin
          Result:=StringReplace(Result,'.','',[rfReplaceAll]);
          Result:=StringReplace(Result,',','.',[rfReplaceAll]);
        end;
    end;

end;

destructor TAbstractControl.Destroy;
begin
  inherited Destroy;
end;

function TAbstractControl.GetDBConnection: TSQLConnection;
begin
  Result:=fDBConnection;
end;

function TAbstractControl.GetTD: TTransactionDesc;
begin
  Result:=fTD;
end;

procedure TAbstractControl.SetDBConnection(const Value: TSQLConnection);
begin
  FDBConnection := Value;
end;

procedure TAbstractControl.SetTD(const Value: TTransactionDesc);
begin
  FTD := Value;
end;

end.
